package com.jiangyg.mall.search.controller;

import com.jiangyg.mall.core.support.restful.Result;
import com.jiangyg.mall.search.dto.SkuSearchParamsDTO;
import com.jiangyg.mall.search.dto.SkuSuggestSearchParamsDTO;
import com.jiangyg.mall.search.service.SkuSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 类描述：索引入口服务
 *
 * @author jiangyg
 * @date 2021-12-11
 */
@RestController
@RequestMapping("/search/sku")
public class SkuSearchController {

    /**
     * 商品索引服务
     */
    private final SkuSearchService skuSearchService;

    @Autowired
    public SkuSearchController(SkuSearchService skuSearchService) {
        this.skuSearchService = skuSearchService;
    }

    /**
     * 功能描述：查询商品
     *
     * @param dto 请求参数
     * @return 结果
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("/select")
    public Result<Object> select(@RequestBody SkuSearchParamsDTO dto) throws Exception {
        return Result.ok(skuSearchService.select(dto));
    }

    /**
     * 功能描述：查询商品详情
     *
     * @param skuId skuId
     * @return 结果
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("/details")
    public Result<Object> details(@RequestParam(required = true, name = "id") Long skuId) throws Exception {
        return Result.ok(skuSearchService.details(skuId));
    }

    /**
     * 功能描述：搜索建议
     *
     * @param dto 请求参数
     * @return 结果
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("/suggest")
    public Result<Object> suggest(@RequestBody SkuSuggestSearchParamsDTO dto) throws Exception {
        return Result.ok(skuSearchService.suggest(dto));
    }

}
